# Build recipe for graft.
#
# Copyright (c) 2017-2019, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=graft
version=2.16
arch=noarch
release=6

# Define a category for the output of the package name
pkgcategory=tools

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch="
 https://dragora.mirror.garr.it/current/sources/$tarname
 rsync://rsync.dragora.org/current/sources/$tarname
"
#fetch=http://peters.gormand.com.au/Home/tools/graft/$tarname

description="
A package management utility (version $version).

Graft provides a mechanism for managing multiple packages under a single
directory hierarchy. Packages are installed in self contained directory
trees and symbolic links from a common area are made to the package files.

This approach allows multiple versions of the same package to coexist on
the same system. One version is the commonly available version and
symbolic links will be made to this version. New versions can be tested
and once acceptable can replace the current commonly available version.
Older versions can still be used for legacy systems by using the 'real'
path name to the package instead of the 'common' path name.
"

homepage=https://peters.gormand.com.au/Home/tools/graft
license=GPLv2+

# Source documentation
docs="CHANGES COPYING README THOUGHTS doc/graft.html doc/graft.pdf doc/graft.txt"
docsdir="${docdir}/${program}"

# Limit package name to the program name
full_pkgname="${program}@${pkgcategory}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    cp -f Makefile.dist Makefile

    make \
     PACKAGEDIR=/usr/pkg       \
     TARGETDIR=/               \
     BIN="${destdir}/usr/bin"  \
     MAN="${destdir}/$mandir"  \
     DOC="${destdir}/$docsdir" \
     install

    # Compress manual page
    lzip -9 "${destdir}/${mandir}/man1/graft.1"

    # Copy source documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"

    # Remove shipped .nograft from DOC
    rm -f "${destdir}/$docsdir.nograft"
}

